package com.mmall.controller.protal;

import com.mmall.common.ServerResponse;
import com.mmall.service.IProductService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/product/")
public class ProductController {

    @Autowired
    private IProductService iProductService;

    @RequestMapping(value = "detail.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse detail(Integer productId){
        return iProductService.detail(productId);
    }


    @RequestMapping(value = "list.do",method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse list(@RequestParam(value = "categoryId",required = false) int categoryId,
                               @RequestParam(value = "keyword",required = false) String keyword,
                               @RequestParam( value = "pageNum",defaultValue = "1") int pageNum,
                               @RequestParam(value = "pageSize",defaultValue = "10") int pageSize,
                               @RequestParam(value = "orderBy",defaultValue = "") String orderBy){
       return iProductService.list(categoryId,keyword,pageNum,pageSize,orderBy);
    }
}
